package com.wowo.ffms.controller;

import com.wowo.ffms.service.UserService;

import javax.mail.Session;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/loginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("uname");
        String pwd = request.getParameter("pwd");
        String code = request.getParameter("code");
        HttpSession session = request.getSession();
        String vcode = (String) session.getAttribute("rand");
        System.out.println(vcode+""+code);
        System.out.println(name+" , "+pwd);
        PrintWriter out = response.getWriter();
        UserService userService = new UserService();
        String result = userService.login(name,pwd,code,vcode);
        out.print(result);
        out.close();

    }
}
